layui.use(['form','upload','jquery','layer'],function() {
    var form = layui.form(),
        $ = layui.jquery,
        layer = layui.layer,
        divshow = parent.divshow;//header区提示信息

    var vm = new Vue({
        el:'#content'
        ,data:{
            show: true
            ,user:{
                id:userid
            }
        }
        ,methods:{
            /**
             * 修改按钮
             */
            update:function () {
                vm.show = false;
                form.render('radio');
                $('#content input[type!=button]').attr("readOnly",false).removeClass("disabled");

            },
            /**
             * 保存按钮
             */
            save:function () {
                var url = "/enterprise/modifyPersonInfo";
                console.log(vm.user.sex);
                $.ajax({
                    type:"POST",
                    url:url,
                    contentType : "application/json; charset=utf-8",
                    data:JSON.stringify(vm.user),
                    dataType:"json",
                    success:function (response) {
                        layer.msg("保存成功",{time:1000},function () {
                            vm.show = true;
                            //当保存操作完成时
                            $('#content input[type!=button]').attr("readOnly",true).addClass("disabled");
                            //同时更新header区提示信息
                            getTips(userid, divshow);
                        });
                    },
                    error:function (msg) {
                        console.log("失败");
                        console.log(msg);
                    }
                });
            },
            /**
             * 返回按钮
             */
            reload:function () {
                vm.show = true;
                $('#content input[type!=button]').attr("readOnly",true).addClass("disabled");
                vm.getInfo(vm.user.id);
            },
            /**
             * 获取信息
             * @param userId
             */
            getInfo:function (userId) {
                $.ajax({
                    type:"GET",
                    url:"/enterprise/searchPersonInfo/"+userId,
                    dataType:"json",
                    success:function (Response) {
                        console.log(Response);
                        vm.user = Response.data;
                    },
                    error:function (msg) {
                        console.log("失败");
                        console.log(msg);
                    }
                });
            }
        }
    });

    //首次需要主动读取
    vm.getInfo(userid);
    $('#content input[type!=button]').attr("readOnly",true).addClass("disabled");

    //监听radio
    form.on('radio(sex)',function (data) {
        vm.user.sex = data.value
    });

});